home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jkarcher@ix.netcom.com(John J. Karcher )
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Random #s
- Date: 22 Mar 1996 17:17:17 GMT
- Organization: Netcom
- Message-ID: <4iunat$jnj@dfw-ixnews3.ix.netcom.com>
- References: <4ihkif$ed0@apollo.isisnet.com> <4irnj8$a2t@dunlop.cs.strath.ac.uk>
- NNTP-Posting-Host: ix-vf4-17.ix.netcom.com
- X-NETCOM-Date: Fri Mar 22 11:17:17 AM CST 1996
-
- In <4irnj8$a2t@dunlop.cs.strath.ac.uk> pcallagh@cs.strath.ac.uk (Paul
- Callaghan) writes:
- >
- >Here is a little program which will generate random numbers
- >(Off the top of my head so it `should` work.)
- >(rand() % MUTATE)+
- >#include <time.h>
- >#define HI 6
- >#define LO 1
- >
- >
- >void main()
- >{
- > int rand_no;
- >
- > srand(time(NULL));
- >
- > rand_no=(rand() % HI)+LO;
- >}
- >
- >This generates a random number between HI and LO every time the
- >program is run.
- >(Doesn`t do anything with it bet generates it anyway :-)<-<)
-
- If my eyes don't deceive me (which they sometimes do), this code will
- work only if LO equals 1. Shouldn't this read:
-
- rand_no = (rand() % (HI - LO)) + LO;
-
- to get a number where LO <= rand_no < HI, or
-
- rand_no = (rand() % ((HI - LO) + 1)) + LO;
-
- to get a number where LO <= rand_no <= HI.
-
- Not to be picky... :^)
-
- John J. Karcher
-
-